package com.yulongtian.oneProblemEveryDay.month202211.day20220922;

/**
 * https://leetcode.cn/problems/check-array-formation-through-concatenation/
 * @author YulongTian
 * @date 2022/9/22 - 8:46
 */
public class Test01 {
    public static void main(String[] args) {
        int[] arr={91,4,64,78};
        int[][] pieces={{78},{4,64},{91}};
        System.out.println(canFormArray(arr, pieces));
    }
    public static boolean canFormArray(int[] arr, int[][] pieces) {
        int index_arr=0;
        boolean flag=false;//是否有相同的
        int length=arr.length;

        while (index_arr<length){
            int temp=arr[index_arr];
            int pre_index_arr=index_arr;
            for(int i=0;i<pieces.length;i++){
                if(pieces[i][0]==temp){
                    flag=true;
                    for(int j=0;j<pieces[i].length;j++){
                        if(pieces[i][j]!=arr[index_arr]){
                            return false;
                        }else{
                            index_arr++;
                        }
                    }
                }
            }
            if(pre_index_arr==index_arr){
                return false;
            }
        }
        if(!flag){
            return false;
        }
        return true;
    }

}
